package com.example.leetcode.tree;

public class Tree8 {

    public static void main(String[] args) {

    }

    public int FindPath (TreeNode root, int sum) {
        if (root == null) {
            return res;
        }
        // 根节点找有无路径
        dfs(root, sum);
        // 左子树找有无路径
        FindPath(root.left, sum);
        // 右子树找有无路径
        FindPath(root.right, sum);
        return res;
    }


    int res = 0;

    public void dfs (TreeNode root, int sum) {
        if (root == null) {
            return;
        }

        if (sum == root.val) {
            res++;
        }

        dfs(root.left, sum - root.val);
        dfs(root.right, sum - root.val);
    }


}
